package com.example.demospringboot.flow.exec;

import org.flowable.common.engine.api.delegate.event.AbstractFlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;

/**
 * 全局事件监听器
 */
public class MyGlobalEventListener extends AbstractFlowableEventListener {

    /**
     * 事件触发执行的方法
     *
     * {@link FlowableEngineEventType}
     * @param event
     */
    @Override
    public void onEvent(FlowableEvent event) {
        System.out.println("---全局事件监听器---"+event.getType().toString());

        if(FlowableEngineEventType.ENTITY_CREATED.equals(event.getType())){
            // 处理任务创建事件
            System.out.println("Task created: " + event);
        }

       /*  if (event instanceof TaskRuntimeEvent) {
            TaskRuntimeEvent taskEvent = (TaskRuntimeEvent) event;
            if (event instanceof TaskCreatedEventImpl) {
                // 处理任务创建事件
                System.out.println("Task created: " + taskEvent);
            } else if (event instanceof TaskAssignedEvent) {
                // 处理任务分配事件
                System.out.println("Task assigned: " + taskEvent);
            } else if (event instanceof TaskCompletedEvent) {
                // 处理任务完成事件
                System.out.println("Task completed: " + taskEvent);
            } else if (event instanceof TaskCancelledEvent) {
                // 处理任务取消事件
                System.out.println("Task cancelled: " + taskEvent);
            } else if (event instanceof TaskSuspendedEvent) {
                // 处理任务挂起事件
                System.out.println("Task suspended: " + taskEvent);
            }
        } */
    }

    /**
     * 上面的 onEvent 方法抛出异常的后续处理动作
     * @return
     *    false :表示忽略onEvent()方法方法中抛出的异常
     *    true :表示onEvent()方法中抛出的异常继续向上传播，导致当前操作失败
     */
    @Override
    public boolean isFailOnException() {
        return false;
    }
}